home *** CD-ROM | disk | FTP | other *** search
/ PC Users 1998 June / Cd Pc Users 9.iso / prog / inst / baslibs / clslastf.cls < prev    next >
Encoding:
Text File  |  1996-08-19  |  3.2 KB  |  169 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "clsLastFiles"
  6. Attribute VB_Creatable = False
  7. Attribute VB_Exposed = False
  8. Option Explicit
  9.  
  10. '
  11. '  An object to maintain the last files
  12. '  opened by a program
  13. '
  14.  
  15. Private LastFiles As New Collection
  16. Private Num As Integer
  17.  
  18. Public Sub Add(file As String)
  19.    If LastFiles.Count = 0 Then
  20.       LastFiles.Add file, UCase(file)
  21.    Else
  22.       On Error Resume Next
  23.       LastFiles.Remove UCase(file)
  24.       LastFiles.Add file, UCase(file), 1
  25.       If LastFiles.Count > Num Then
  26.          LastFiles.Remove LastFiles.Count
  27.       End If
  28.    End If
  29. End Sub
  30.  
  31. '
  32. '  Clears all files from the list.
  33. '
  34. Public Sub Clear()
  35.    Do While LastFiles.Count > 0
  36.       LastFiles.Remove 1
  37.    Loop
  38. End Sub
  39.  
  40. '
  41. '  Returns the number of files in the list.
  42. '
  43. Public Property Get Count() As Long
  44.    Count = LastFiles.Count
  45. End Property
  46.  
  47. '
  48. '
  49. ' Returns the nth item from the list
  50. '
  51. Public Property Get Item(i As Integer) As String
  52.    On Error GoTo ItemError
  53.    Item = LastFiles(i)
  54.    Exit Property
  55.    
  56. ItemError:
  57.    Item = ""
  58. End Property
  59.  
  60. Public Sub Load(Optional appname As Variant)
  61.    Dim v As Variant
  62.    Dim i As Integer
  63.    Dim j As Integer
  64.    Dim AppN As String
  65.    
  66.    If IsMissing(appname) Then
  67.       AppN = App.ProductName
  68.    Else
  69.       AppN = CStr(appname)
  70.    End If
  71.  
  72.    v = GetAllSettings(AppN, "LastFiles")
  73.    
  74.    If Not IsEmpty(v) Then
  75.       i = UBound(v, 1)
  76.       Me.Clear
  77.       LastFiles.Add v(i, 1), UCase(v(i, 1))
  78.       
  79.       For j = i - 1 To LBound(v, 1) Step -1
  80.          LastFiles.Add v(j, 1), UCase(v(j, 1)), 1
  81.       Next j
  82.    End If
  83. End Sub
  84. '
  85. '  Gets the maximum size of the list.
  86. '
  87. Public Property Get Number() As Integer
  88.    Number = Num
  89. End Property
  90.  
  91. '
  92. '  Sets the maximum size of the list.
  93. '
  94. Public Property Let Number(i As Integer)
  95.    Num = i
  96. End Property
  97.  
  98.  
  99. Public Sub Remove(file As String)
  100.    On Error Resume Next
  101.    LastFiles.Remove UCase(file)
  102. End Sub
  103.  
  104. Public Sub Save(Optional appname As Variant)
  105.    Dim i As Integer
  106.    Dim AppN As String
  107.    
  108.    On Error Resume Next
  109.    
  110.    If IsMissing(appname) Then
  111.       AppN = App.ProductName
  112.    Else
  113.       AppN = CStr(appname)
  114.    End If
  115.       
  116.    DeleteSetting AppN, "LastFiles"
  117.    
  118.    For i = 1 To LastFiles.Count
  119.       SaveSetting AppN, "LastFiles", i, LastFiles(i)
  120.    Next i
  121. End Sub
  122. '
  123. '  Note:  The form must contain a menu control array
  124. '         named mnuLastFiles that is at least as big
  125. '         as Number.
  126. '
  127. '
  128. Public Sub Update(f As Form)
  129.    Dim i As Long
  130.    
  131.   
  132. On Error GoTo NextStep
  133.    For i = 1 To Num
  134.       f.mnuLastFiles(i).Visible = False
  135.    Next i
  136.  
  137. NextStep:
  138.  
  139. On Error GoTo MenuEnd
  140.    If LastFiles.Count > 0 Then
  141.       f.mnuLastFiles(0).Visible = True
  142.       
  143.       For i = 1 To LastFiles.Count
  144.          f.mnuLastFiles(i).Caption = LastFiles(i)
  145.          f.mnuLastFiles(i).Visible = True
  146.       Next i
  147.       
  148.       Do
  149.         f.mnuLastFiles(i).Visible = False
  150.         i = i + 1
  151.       Loop
  152.    Else
  153.       i = 0
  154.       Do
  155.         f.mnuLastFiles(i).Visible = False
  156.         i = i + 1
  157.       Loop
  158.    End If
  159.    
  160. MenuEnd:
  161. End Sub
  162.  
  163.  
  164. Private Sub Class_Initialize()
  165.    Num = 5
  166. End Sub
  167.  
  168.  
  169.